export default {
	data() {
		return {
            m2 : 2097152,
		}
	},
	computed: {

	},
	methods: {
		async lb_sign() {
			var promise = new Promise((resolve, reject) => {
				let url = this.site_url + 'api/index/getOssSign';
				this.areq(url).then(res => {
					resolve(res);
				})
			});
			return promise;
		},
		async oss_api(filep){
			var promise = new Promise( async (resolve, reject) => {
				let res = await this.lb_sign();
				if (res.code == 1) {
					let ret = res.data;
					let params = {
						key: ret.filename,
						policy: ret.policy, //后台获取超时时间
						OSSAccessKeyId: ret.accessid, //后台获取临时ID
						success_action_status: '200', //让服务端返回200,不然，默认会返回204
						signature: ret.signature //后台获取签名
					};
					uni.uploadFile({
							url: ret.host, //仅为示例，非真实的接口地址
							filePath: filep,
							fileType: 'image',
							formData: params,
							name: 'file',
							success: async (uploadFileRes) => {
								resolve({code: 1,msg: '上传成功',url: this.oss_url + ret.filename});
							},
							fail(err) {
								reject({code: 0,msg: '上传失败'});
							}
							});
					}else {
						reject(res);
					}
			});
			
			return promise;
		}
			
		}

	}